
*************************************************************************************;

/* 	    		 This file reproduce Table 8 Panel A: Funding Cost					*/

*************************************************************************************;

libname rep "C:\Users\~";

data temp; set rep.mydata; run; 

data regbase; set temp;
mflev_low = active_low* ted_rank; mflev_high = active_high* ted_rank;
hflev_low = hfflow_low* ted_rank; hflev_high = hfflow_high* ted_rank; run;


option missing = " ";
%macro print;
data N; set N; Estimate = nValue1; if Label1 = "Used"; run;
data Nobs; set N; Parameter = "N"; keep EstType Parameter Estimate; run;
data r2; set fit; Parameter = "RSQ"; keep EstType Parameter RSquare; rename RSquare = Estimate;  run;
data adjr2; set fit; Parameter = "AdjRSQ"; keep EstType Parameter AdjRsq; rename AdjRSq = Estimate;  run;
data final; set parest Nobs r2 adjr2; drop EstType StdErr Probt DF; run;
data final&i; set final; rename Estimate = syy_&freq tValue = t_&freq; 
if Parameter not in ("h_freq", "hl_freq", "a_freq", "al_freq", "N", "RSQ") then delete; run;
%mend;

%macro decomp ;

%do i=1 %to 2;
%if &i =1 %then %do; %let freq = low; %let con = high; %end; 
%else %do; %let freq = high; %let con = low; %end;
ods output "Nonlinear GMM Summary of Residual Errors" = fit;
ods output "Nonlinear GMM Parameter Estimates" = parest;
ods output "Estimation Summary Statistics" = N;
proc model data=regbase plot =none;
endo syy_&freq; exog ted_rank active_low active_high hfflow_low hfflow_high mflev_low mflev_high hflev_low hflev_high mktrf amihud tover hml smb; instruments _exog_;
syy_&freq =b0 +r0*ted_rank +h_freq *hfflow_&freq +h_con*hfflow_&con +hl_freq *hflev_&freq +h1_con *hflev_&con 
+a_freq*active_low +a_con*active_high +al_freq *mflev_&freq + al_con*mflev_&con +b1*mktrf +b2*amihud +b3*tover +b4*hml +b5*smb;
fit syy_&freq / gmm kernel=(bart,13,0) vardef=n; run; quit; 
%print;
%end;

data T8A; merge final1 final2; run;

%mend;

%decomp;

proc print data = T8A noobs; run;
